﻿Imports BUS
Imports DTO

Public Class MH_ThayDoiQuyDinh

    Dim thsoDTO As New ThamSoDTO


    Private Sub MH_ThayDoiQuyDinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        pnlTuoi.Enabled = False
        pnlSiSo.Enabled = False
        pnlSoLuongMon.Enabled = False
        pnlDiemChuan.Enabled = False
        KiemTraCheckBox()

        Dim bangThamSo As New DataTable
        Dim tsBUS As New ThamSoBUS
        bangThamSo = tsBUS.LayBang()
        Dim row As DataRow = bangThamSo.Rows(0) 'Bảng tham số chỉ có 1 dòng

        thsoDTO.TuoiToiThieu = row("TuoiToiThieu")
        thsoDTO.TuoiToiDa = row("TuoiToiDa")
        thsoDTO.SiSoToiDa = row("SiSoToiDa1Lop")
        thsoDTO.SoMonHoc = row("SoMonHoc")
        thsoDTO.DiemChuanDatMon = row("DiemChuanDatMon")

        nudTuoiToiThieu.Value = thsoDTO.TuoiToiThieu
        nudTuoiToiDa.Value = thsoDTO.TuoiToiDa
        nudSiSo.Value = thsoDTO.SiSoToiDa
        nudSoMon.Value = thsoDTO.SoMonHoc
        nudDiemChuan.Value = thsoDTO.DiemChuanDatMon

    End Sub

    Private Sub chkTuoi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTuoi.CheckedChanged
        If (chkTuoi.Checked = True) Then
            pnlTuoi.Enabled = True
        Else
            pnlTuoi.Enabled = False
        End If
        nudTuoiToiThieu.Value = thsoDTO.TuoiToiThieu
        nudTuoiToiDa.Value = thsoDTO.TuoiToiDa

        KiemTraCheckBox()
    End Sub

    Private Sub chkSiSo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSiSo.CheckedChanged
        If (chkSiSo.Checked = True) Then
            pnlSiSo.Enabled = True
        Else
            pnlSiSo.Enabled = False
        End If
        nudSiSo.Value = thsoDTO.SiSoToiDa

        KiemTraCheckBox()
    End Sub

    Private Sub chkSoLuongMon_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSoLuongMon.CheckedChanged
        If (chkSoLuongMon.Checked = True) Then
            pnlSoLuongMon.Enabled = True
        Else
            pnlSoLuongMon.Enabled = False
        End If
        nudSoMon.Value = thsoDTO.SoMonHoc

        KiemTraCheckBox()
    End Sub

    Private Sub chkDiemChuan_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDiemChuan.CheckedChanged

        If (chkDiemChuan.Checked = True) Then
            pnlDiemChuan.Enabled = True
        Else
            pnlDiemChuan.Enabled = False
        End If
        nudDiemChuan.Value = thsoDTO.DiemChuanDatMon

        KiemTraCheckBox()
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub btnCapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhat.Click
        thsoDTO.TuoiToiThieu = nudTuoiToiThieu.Value
        thsoDTO.TuoiToiDa = nudTuoiToiDa.Value
        thsoDTO.SiSoToiDa = nudSiSo.Value
        thsoDTO.SoMonHoc = nudSoMon.Value
        thsoDTO.DiemChuanDatMon = nudDiemChuan.Value

        Dim thsoBUS As New ThamSoBUS
        Dim kq As Integer = thsoBUS.CapNhatBang(thsoDTO)

        If kq = 1 Then
            MessageBox.Show("Cập nhật thay đổi thành công.")
        Else
            MessageBox.Show("Cập nhật thay đổi thất bại.")
        End If

    End Sub

    Private Sub KiemTraCheckBox()

        If (chkTuoi.Checked = False And chkSoLuongMon.Checked = False And chkSiSo.Checked = False And chkDiemChuan.Checked = False) Then
            btnCapNhat.Enabled = False
        Else
            btnCapNhat.Enabled = True
        End If

    End Sub
End Class